﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Dal;

public partial class Account_ReturnRatio : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindList();
        }
    }


    /// <summary>
    /// 绑定数据
    /// </summary>
    private void BindList()
    {
        gridList.DataSource = AccountInfo.GetReturnRatio();
        gridList.DataBind();
     }

    /// <summary>
    /// 点击 编辑
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridList.EditIndex = e.NewEditIndex;
        BindList();
    }


    /// <summary>
    /// 点击取消
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        lblWarn.Text = "";
        gridList.EditIndex = -1;
        BindList();
    }


    
    //点击 更新
    protected void gridList_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int rewardID = 0;
        double ratio;
    //  string rewardName = ((TextBox)gridList.Rows[e.RowIndex].FindControl("txtRewardName")).Text.Trim();
        
        try
        {
            rewardID = Convert.ToInt32(gridList.DataKeys[e.RowIndex].Values[0].ToString());
        }
        catch (Exception ex)
        {

        }

        //if (rewardName == "")
        //{
        //    lblWarn.Text = "请输入等级名称！";
        //    return;
        //}
        
        try
        {
            ratio = Convert.ToDouble(((TextBox)gridList.Rows[e.RowIndex].FindControl("txtRatio")).Text.Trim());
        }
        catch (Exception ex)
        {
            lblWarn.Text = "请输入正确的数据格式！";
            return;
        }

        bool b = AccountInfo.UpdateReturnRatio(rewardID, ratio);
        if (b)
        {
            lblWarn.Text = "更新成功！";
            gridList.EditIndex = -1;
            BindList();
        }

    }

}